luci-mod-dashboard: use localized time
authorAndy Chiang <[email protected]>
Wed, 15 Oct 2025 17:48:55 +0000 (00:48 +0700)
committerPaul Donald <[email protected]>
Mon, 20 Oct 2025 18:40:46 +0000 (20:40 +0200)
use localized time

Signed-off-by: Andy Chiang <[email protected]>
modules/luci-mod-dashboard/htdocs/luci-static/resources/view/dashboard/include/10_router.js
modules/luci-mod-dashboard/root/usr/share/rpcd/acl.d/luci-mod-dashboard.json

index d97fc9cadf93cc6eb9ff2f64d7ff95fffa340a80..8005ff67448f101e105e88b326a5735d50c1c245 100644 (file)
@@ -3,6 +3,7 @@
 'require fs';
 'require rpc';
 'require network';
+'require uci';
 
 var callSystemBoard = rpc.declare({
        object: 'system',
@@ -14,6 +15,12 @@ var callSystemInfo = rpc.declare({
        method: 'info'
 });
 
+var callGetUnixtime = rpc.declare({
+       object: 'luci',
+       method: 'getUnixtime',
+       expect: { result: 0 }
+});
+
 return baseclass.extend({
 
        params: [],
@@ -23,7 +30,9 @@ return baseclass.extend({
                        network.getWANNetworks(),
                        network.getWAN6Networks(),
                        L.resolveDefault(callSystemBoard(), {}),
-                       L.resolveDefault(callSystemInfo(), {})
+                       L.resolveDefault(callSystemInfo(), {}),
+                       L.resolveDefault(callGetUnixtime(), 0),
+                       uci.load('system')
                ]);
        },
 
@@ -298,20 +307,22 @@ return baseclass.extend({
 
                const boardinfo   = data[2];
                const systeminfo  = data[3];
+               const unixtime    = data[4];
 
                let datestr = null;
 
-               if (systeminfo.localtime) {
-                       const date = new Date(systeminfo.localtime * 1000);
-
-                       datestr = '%04d-%02d-%02d %02d:%02d:%02d'.format(
-                               date.getUTCFullYear(),
-                               date.getUTCMonth() + 1,
-                               date.getUTCDate(),
-                               date.getUTCHours(),
-                               date.getUTCMinutes(),
-                               date.getUTCSeconds()
-                       );
+               if (unixtime) {
+                       const date = new Date(unixtime * 1000);
+                       const zn = uci.get('system', '@system[0]', 'zonename')?.replaceAll(' ', '_') || 'UTC';
+                       const ts = uci.get('system', '@system[0]', 'clock_timestyle');
+                       const hc = uci.get('system', '@system[0]', 'clock_hourcycle');
+
+                       datestr = new Intl.DateTimeFormat(undefined, {
+                               dateStyle: 'medium',
+                               timeStyle: (ts == 0) ? 'long' : 'full',
+                               hourCycle: hc,
+                               timeZone: zn
+                       }).format(date);
                }
 
                this.params.router = {
index 1f331e7b4b8179078f1d773f8070c789b183c342..023122a3c24f4cb923ab65f4447ce08ba2d59b5e 100644 (file)
@@ -16,6 +16,7 @@
                        },
                        "ubus": {
                                "file": [ "list", "read" ],
+                               "luci": [ "getUnixtime" ],
                                "system": [ "board", "info" ]
                        }
                }